package com.sc.nft.dao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.DigitalCollection;
import com.sc.nft.entity.vo.SeriesListVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.CatenaInfo;
import com.sc.nft.mapper.CatenaInfoMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_catena_info)数据DAO
 *
 * @author Sun
 * @since 2022-05-30 13:22:00
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class CatenaInfoDao extends ServiceImpl<CatenaInfoMapper, CatenaInfo> {

    public List<CatenaInfo> seriesList(Integer type) {
        LambdaQueryWrapper<CatenaInfo> wrapper =new LambdaQueryWrapper<CatenaInfo>();
        wrapper.eq(CatenaInfo::getType,type);

        return list(wrapper);
    }

    public Page<CatenaInfo> catenaList(int pageNo, int pageSize, String name) {
        LambdaQueryWrapper<CatenaInfo>wrapper=new LambdaQueryWrapper<>();
        wrapper.like(name!=null,CatenaInfo::getName,name);
        wrapper.orderByDesc(CatenaInfo::getId);
        return page(new Page<>(pageNo,pageSize),wrapper);
    }

    public String getCatenaNameById(Long catenaId) {
        LambdaQueryWrapper<CatenaInfo>wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(CatenaInfo::getId,catenaId);
        wrapper.select(CatenaInfo::getName);
        CatenaInfo catenaInfo = getOne(wrapper);
        return catenaInfo.getName();
    }
}